package cn.zhizihua.service.impl;

import cn.zhizihua.exception.AppException;
import cn.zhizihua.exception.AppExceptionCodeMsg;
import cn.zhizihua.mapper.AddressMapper;
import cn.zhizihua.pojo.Address;
import cn.zhizihua.query.AddressQuery;
import cn.zhizihua.query.BaseQuery;
import cn.zhizihua.service.IAddressService;
import cn.zhizihua.vo.PageBean;
import cn.zhizihua.vo.ResultBean;
import com.alibaba.druid.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AddressService extends BaseService<Address> implements IAddressService {

    @Autowired
    AddressMapper addressMapper;


    @Transactional(readOnly = true)
    @Override
    public ResultBean getByUserId(Integer userId) {

        //参数校验
        if (userId==null || userId==0){
            //抛自定义异常 请求参数为空
            throw new AppException(AppExceptionCodeMsg.PARAMS_EMPTY);
        }

        List<Address> addressList = addressMapper.getByUserId(userId);

        return ResultBean.SUCCESS(addressList);
    }
}
